package cao.ptit.skyforce;

import android.R.color;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapRegionDecoder;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

//day la giao dien game

public class gameview extends View{
	private Paint paint;
	private Bitmap bitmapanh;
	private float xhand = 100, yhand = 300;

	// xay dung phuong thuc khoi tao
	public gameview(Context context) {
		// TODO Auto-generated constructor stub
		super(context);
		paint = new Paint();
		paint.setColor(Color.BLUE);
		paint.setStrokeWidth(10);
		paint.setStyle(Style.STROKE);
		bitmapanh = BitmapFactory.decodeResource(getResources(),
				R.drawable.ic_launcher);
	}

	@Override
	// phuong thuc de ve tat ca cac nhan vat game
	protected void onDraw(Canvas canvas) {
		// TODO Auto-generated method stub
		super.onDraw(canvas);
		canvas.drawColor(color.white);
		canvas.drawLine(0, 0, 300, 300, paint);// ve duong thang
		canvas.drawRect(50, 20, 300, 100, paint);// hinh cn
		canvas.drawBitmap(bitmapanh, xhand, yhand, null);// ve nhan vat game

	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		// TODO Auto-generated method stub
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:

			Log.d("ACTIONDOWN", "action down");
			break;
		case MotionEvent.ACTION_UP:

			Log.d("ACTIONDOWN1", "action up");
			break;
		case MotionEvent.ACTION_MOVE:
			invalidate();// dung phuong thuc nay de goi ham ondraw(),se ve lai
							// cac nhan vat
			xhand = event.getX();
			yhand = event.getY();

			break;

		default:
			break;
		}
		return true;
	}

}
